package com.sunday.common.dubbo.tools.consumer;

import com.sunday.common.core.constants.LogConstants;
import com.sunday.common.core.enums.ErrorCodeEnum;
import com.sunday.common.core.remoting.base.response.Response;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.common.dubbo.tools.provider.Provider;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/test")
public class ConsumerImpl {

    //    @DubboReference(check = false)
//    @DubboReference(registry = "test1")
    @DubboReference
    Provider provider;

    @GetMapping("list")
    public RestResponse<?> list() {
        try {
            log.info(LogConstants.rpc_request_format);
            Response response = provider.save("john");
            log.info(LogConstants.rpc_response_format, response);
            return RestResponse.resultReturn(response);
        } catch (Exception e) {
            log.error(e.toString());
        }
        return RestResponse.error(ErrorCodeEnum.A0_001);
    }

}
